package com;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        Integer count = 5;
        Integer[] array= new Integer[count];
        for (int i = 0; i < count; i++) {
            Integer value = null;
            do {
                try {
                    System.out.println(MessageFormat.format("请输入第{0}个参数",String.valueOf(i+1)));
                    Scanner scanner = new Scanner(System.in);
                    value = scanner.nextInt();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }while (Objects.isNull(value));
            array[i]=value;
        }

        Integer sum =  Arrays.stream(array).collect(Collectors.summingInt(Integer::intValue));
        System.out.println(MessageFormat.format("数组之和为：{0}",String.valueOf(sum)));
    }


}
